$(function () {
    layui.use(['form', 'element', 'laytpl'], function () {
        var form = layui.form(),
            element = layui.element();

        //获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
        var layid = location.hash.replace(/^#reviewTab=/, '');
        element.tabChange('reviewTab', layid);

        //监听Tab切换，以改变地址hash值
        element.on('tab(reviewTab)', function(){
            location.hash = 'reviewTab='+ this.getAttribute('lay-id');
        });

        //监听保存
        form.on('submit(save)', function (data) {
            console.log(data.field);
            $.post('/Home/Posts/post', data.field, function(response) {
                if (response.code == 0) {

                } else {
                    layer.msg(response.msg, {icon: 2})
                }
            }, 'json');
        });
    });
});